package com.example.managementjava.course;

import com.example.managementjava.DB_message;
import com.example.managementjava.Student.Student;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class DB_Cou {
    private static String url = DB_message.getUrl();
    private static String user= DB_message.getUser();
    private static String pswd = DB_message.getPswd();
    // 全部学生
    public static List<Course> selectAlllist(){
        List<Course> list= new ArrayList<>();
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager.getConnection(url, user, pswd);
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("select  * from course");
            while (resultSet.next()){
                String studentid = resultSet.getString(1);
                String NAME = resultSet.getString(2);
                String class1 = resultSet.getString(3);
                String score = resultSet.getString(4);
                String credits = resultSet.getString(5);
                String gpa = resultSet.getString(6);
                String pass = resultSet.getString(6);
                Course course = new Course(studentid,NAME, class1,score,credits,gpa,pass);
//                System.out.println(student.toString());
                list.add(course);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
